cmake_minimum_required(VERSION 3.10)

# 项目名称
project(PthreadExample VERSION 1.0.0 LANGUAGES C CXX)

# 设置 C/C++ 标准
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)

# 编译选项
# option(BUILD_COMMON_LIB "Build common library" OFF)
option(BUILD_TESTS "Build test cases" OFF)
option(ENABLE_WARNINGS "Enable warnings" ON)
option(ENABLE_POSIX "Enable posix" ON)
option(ENABLE_FILE_IO "Enable file io" ON)


# 设置编译标志
if(ENABLE_WARNINGS)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -g")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -g")
endif()


# 添加头文件目录
# include_directories(
#     ${CMAKE_SOURCE_DIR}/inc
# )

# 查找所需的包
find_package(Threads REQUIRED)

# # 条件编译 common 库
# if(BUILD_COMMON_LIB)
#     file(GLOB_RECURSE COMMON_SOURCES "src/common/*.c")
#     if(COMMON_SOURCES)
#         add_library(common_lib STATIC ${COMMON_SOURCES})
#         set(EXTRA_LIBS common_lib)
#     else()
#         message(WARNING "No source files found in common directory")
#     endif()
# endif()

if(ENABLE_POSIX)
    add_subdirectory(src/posix)
endif()

if(ENABLE_FILE_IO)
    add_subdirectory(src/file_io)
endif()

# 条件编译测试用例
if(BUILD_TESTS)
    enable_testing()
    add_subdirectory(tests)
endif()